package handler

import (
	"context"
	"github.com/gin-gonic/gin"
	"net/http"
	"product-announcement/api/request"
	"product-announcement/global"
	"product-announcement/internal/dao"
	"product-announcement/internal/model"
	"time"
)

func CreateOrder(c *gin.Context) {
	var req request.CreateOrderForm
	var order model.Order

	if req.UserId == 0 || req.Price == 0 {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}

	order = model.Order{
		UserId: req.UserId,
		Price:  req.Price,
	}

	err := dao.AddFile(&order)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "订单生成失败",
			"data": false,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "订单生成成功",
		"data": true,
	})

	global.RDB.Set(context.Background(), "order_queue", order, time.Hour*24)

}

func ListOrder(c *gin.Context) {
	
}